{extend name="ashippingmanagement/Public/base" /}
{block name="container"}
<style>
    .is_hiddenTr {
        display: none;
    }
</style>

<!-- 标题 -->
<div class="page-heade" style="border: 1px solid #000">
    <h1 class="title_color">历史发运数据导入</h1>
</div>
<!-- 标题 -->
<table class="table table-bordered" style="margin: 0">
    <tr>
        <td>
            <form id="form_id" action="" class="form-inline" method="post">
                请选择导入月份：
                <select name="n" id="n" class="form-control validate[required]"
                        style="display: inline-block;width: 140px">
                    <option value="2020">2020</option>
                    <option value="2019">2019</option>
                    <option value="2018">2018</option>
                    <option value="2017">2017</option>
                    <option value="2016">2016</option>
                    <option value="2015">2015</option>
                    <option value="2014">2014</option>
                    <option value="2013">2013</option>
                    <option value="2012">2012</option>
                    <option value="2011">2011</option>
                    <option value="2010">2010</option>
                    <option value="2009">2009</option>
                    <option value="2008">2008</option>
                    <option value="2007">2007</option>
                    <option value="2006">2006</option>
                    <option value="2005">2005</option>
                </select>年
                <select name="y" id="y" class="form-control validate[required]"
                        style="display: inline-block;width: 140px">
                    <option value="12">12</option>
                    <option value="11">11</option>
                    <option value="10">10</option>
                    <option value="09">09</option>
                    <option value="08">08</option>
                    <option value="07">07</option>
                    <option value="06">06</option>
                    <option value="05">05</option>
                    <option value="04">04</option>
                    <option value="03">03</option>
                    <option value="02">02</option>
                    <option value="01">01</option>
                </select>月
                <span class="lr_5"></span>
                <button class="btn btn-info" type="submit">查询</button>
            </form>
            <script>
                $('#n').val("<?php if(isset($where['n'])) echo $where['n']; ?>");
                $('#y').val("<?php if(isset($where['y'])) echo $where['y']; ?>");
            </script>
        </td>
    </tr>
    <tr>
        <td>
            <p class="padding-10">{$data['ny']}共有<span>{$data['sum']['count']}</span>行发运记录，折后销售额合计：<span
                    class="font-bold ObjectNum">{$data['sum']['fyZheMoney']}</span>元</p>
            <p>数据最新更新日期为：<span class="font-bold">{$data['date']['date']}</span> 更新人：<span id="">{$data['date']['operator']}</span>
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <p class="colorRed">
                温馨提示：在导入您的新发运数据之前，请确认新发运数据在销路通系统中是否存在，如果销路通系统中已存在，导入后将出现重复数据。您新导入的数据应不包含之前已导入的部分，请您确认所导入的数据完整并正确无误。</p>
            <p class="padding-10 font-bold">Excel文件导入注意事项：</p>
            <p>1.必须项：售达方经销商编号、产品编码、数量、发运金额、发运日期、订单号、发运单号、销售人员。</p>
            <p class="padding-10">2.必须填写数字：数量、发运金额。</p>
            <p>3.发运月份只能为一个月，并且要与选择的导入月份保持一致。</p>
            <p class="padding-10">4.销售人员必须是销路通系统中已存在的职员名称。</p>
            <p><span class="font-bold">Excel文件导入格式：</span><a
                    href="{:url('Ashippingmanagement/downFile')}?path=/static/fy/file.xls">产品发运数据导入表格格式.xls</a><span
                    class="colorRed">注：Excel中标记为红色底色的列为必填项。</span></p>
        </td>
    </tr>
</table>
<table id="table" class="table table-bordered text-center table-hover">
    <tr class="info">
        <th class="text-center">日期</th>
        <th class="text-center">导入发运数据行数</th>
        <th class="text-center">折后销售额(元)</th>
        <th class="text-center">备注</th>
    </tr>
    {volist name="data1" id="val"}
    <tr class="count">
        <td>{$val['ny']}月</td>
        <td class="text-right rows">{$val['rows']}</td>
        <td class="text-right zmoney"><span class="ObjectNum">{$val['zmoney']}</span></td>
        <td class="id" style="display: none">{$val['id']}</td>
        <td class="des" style="display: none">{$val['des']}</td>
        <td class="desUser" style="display: none">{$val['desUser']}</td>
        <td class="handleTd">
            {empty name="val['des']"}
            <a href="javascript:;" class="btn btn-white addInfo">增加</a>
            {else /}
            <a href="javascript:;" class="btn btn-white seeBtn">查看</a><span class="lr_5"></span><a href="javascript:;" class="btn-white btn modifyBtn">修改</a>
            {/empty}
        </td>
    </tr>
    <tr class="is_hiddenTr">
        <td colspan="3" class="text-left">
            <div>
                {empty name="$val['des']"}
                <textarea name="des" id="Areatext2"
                          style="user-select:none;width: 60%;max-width:60%;height: 60px;float: left;"
                          class="form-control Areatext">{$val['des']}</textarea><span
                    style="padding-top: 41px;display:inherit">(500)</span>
                {else /}
                <p class='padding-10'>备注人：<span>{$val['desUser']}</span></p>
                <p>内容：<span>{$val['des']}</span></p>
                {/empty}
            </div>
        </td>
        <td><a href="javascript:;" class="btn btn-white sureBtn">确定</a><span class="lr_5"></span><a href="javascript:;" class="btn-white btn closeBtn">关闭</a>
        </td>
    </tr>
    {/volist}
    <tfoot>
    <tr class="text-right success">
        <td>合计</td>
        <td id="str">12</td>
        <td id="str1">12</td>
        <td></td>
    </tr>
    </tfoot>
</table>
<script>
    var rows = zmoney = 0;
    $('.count').each(function () {
        rows += parseFloat($(this).find('.rows').text());
        zmoney += parseFloat($(this).find('.zmoney').text());
    })
    $('#str').text(rows);
    $('#str1').text(zmoney);
    //表单验证
    $('#form_id').validationEngine('attach', {
        promptPosition: 'bottomRight'
    });
    $(document).ready(function () {
        var $ObjectNum = $(".ObjectNum");
        toNum($ObjectNum);
    })

    /*弹出隐藏的tr*/
    $(document).on("click", '.addInfo', function () {
        // var $addInfoTr = $('.is_hiddenTr');
        $(this).parent().parent().next('tr').toggle();
    })
    $(document).on("click", '.closeBtn', function () {
        // // console.log($(this))
        $(this).parent().parent().hide();
    })

    /*确定按钮*/
    $(document).on("click", ".sureBtn", function () {
        // var strBtn = '<a href="javascript:;" class="btn btn-white seeBtn">查看</a><span class="lr_5"></span><a href="javascript:;" class="btn-white btn modifyBtn">修改</a>'
        // $(this).parent().parent().prev('tr').find('.handleTd').html(strBtn)
        // $(this).parent().parent().hide();
        var pid = $(this).parent().parent().prev('tr').find('.id').text();
        var des = $(this).parent().parent().prev('tr').find('.des').text();
        var des1 = $(this).parent().prev('td').find('#Areatext2').val();
        if(des1 != ''){
            des = des1;
        }
        $.post("{:url('Ashippingmanagement/des')}",{pid:pid,des:des},function (re){
            if(re.success){
                location.reload();
            }else{
                sweetAlert("", re.msg, "error");
            }
        },'json');
    })

    /*修改按钮*/
    $(document).on("click", ".modifyBtn", function () {
        var des = $(this).parent().siblings('.des').text();
        var des1 = '<textarea name="des" id="Areatext2" style="user-select:none;width: 60%;max-width:60%;height: 60px;float: left;" class="form-control Areatext">'+des+'</textarea><span style="padding-top: 41px;display:inherit">(500)</span>';
        $(this).parent().parent().next("tr").toggle();
        $(this).parent().parent().next("tr").find('div').html(des1);
    })
    /*查看按钮*/
    $(document).on("click", '.seeBtn', function () {
        var str = $(this).parent().siblings('.des').text();
        var str1 = $(this).parent().siblings('.desUser').text();
        var str2 = "<p class='padding-10'>备注人：<span>"+str1+"</span></p><p>内容：<span>"+str+"</span></p>";
        var $addInfoTr = $(this).parent().parent().next('tr')
        $addInfoTr.toggle();
        $(this).parent().parent().next('tr').find('div').html(str2);
    })

</script>
{/block}